package com.ky.serialport.sensor;

import com.ky.serialport.bean.ComBean;
import com.ky.serialport.utils.MyFunc;

import static com.ky.serialport.utils.RandomUtils.myRandom;

/**
 * 过速传感器
 */
public class GuoSuBean {

    public byte[] bRec;
    public Long time;
    public int guosuVel; //过速
    public int power; // 电量
    public int signal; //信号
    public ComBean comBean;

    public GuoSuBean() {

    }

    public GuoSuBean(ComBean comBean ) {
        time = comBean.recTime;
        this.comBean = comBean;
        caculate(comBean.recData);
    }

    public GuoSuBean(byte[] recData) {
        caculate(recData);
        time = System.currentTimeMillis();
    }

    public GuoSuBean caculate(ComBean comBean){
        time = comBean.recTime;
        this.comBean = comBean;
        return caculate(comBean.recData);
    }


    public GuoSuBean caculate(byte[] bRec) {
        guosuVel =  MyFunc.twoByte2IntNoSign(bRec[14], bRec[15]);
        power = MyFunc.getPower(bRec[18],bRec[19]);
        signal = MyFunc.getSignal(bRec[20]);
        this.bRec = bRec;
        return this;
    }

    public GuoSuBean test() {
        time = System.currentTimeMillis();
        power = 300 + myRandom.nextInt(120);
        signal = 200;
        guosuVel =  20 + myRandom.nextInt(5);
        return this;
    }

}
